package com.ganeshkrishnan.globald.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.ganeshkrishnan.globald.abstracts.BaseObject;

@Entity
public class Person extends BaseObject {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Long id;
	private String firstName;
	private String lastName;
	private int PowerLevel;
	private int Level;
	private int Karma;
	private Set<CivResource> resource;
	private Set<MilResource> milresource;
	private Set<PersonLocation> location;
	private CountryDetail countryCode;

	public Person() {
	}

	@Id
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "PersonID")
	public Set<CivResource> getResource() {
		return resource;
	}

	public void setResource(Set<CivResource> resource) {
		this.resource = resource;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "PersonID")
	public Set<MilResource> getMilresource() {
		return milresource;
	}

	public void setMilresource(Set<MilResource> milresource) {
		this.milresource = milresource;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "PersonID")
	public Set<PersonLocation> getLocation() {
		return location;
	}

	public void setLocation(Set<PersonLocation> location) {
		this.location = location;
	}

	@Column(name = "first_name", length = 50)
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(name = "last_name", length = 50)
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "CountryCode")
	public CountryDetail getCountryCode() {
		return countryCode;
	}

	public void setCountryCode(CountryDetail countryCode) {
		this.countryCode = countryCode;
	}

	public int getPowerLevel() {
		return PowerLevel;
	}

	public void setPowerLevel(int powerLevel) {
		PowerLevel = powerLevel;
	}

	public int getLevel() {
		return Level;
	}

	public void setLevel(int level) {
		Level = level;
	}

	public int getKarma() {
		return Karma;
	}

	public void setKarma(int karma) {
		Karma = karma;
	}

	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Person person = (Person) o;
		if (id != person.id) return false;
		//if (firstName != null ? !firstName.equals(person.firstName) : person.firstName != null) return false;
		//if (lastName != null ? !lastName.equals(person.lastName) : person.lastName != null) return false;
		return true;
	}

	public int hashCode() {
		int result;
		result = (firstName != null ? firstName.hashCode() : 0);
		result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
		return result + (id != null ? id.hashCode() : 0);
	}

	public String toString() {
		return "PersonX{" + "id=" + id + ", firstName='" + firstName + " '" + ", lastName='" + lastName + "' " + '}';
	}
}
